(*
  Copyright (c) 2009 Barry Schwartz

  Permission is hereby granted, free of charge, to any person
  obtaining a copy of this software and associated documentation
  files (the "Software"), to deal in the Software without
  restriction, including without limitation the rights to use,
  copy, modify, merge, publish, distribute, sublicense, and/or sell
  copies of the Software, and to permit persons to whom the
  Software is furnished to do so, subject to the following
  conditions:

  The above copyright notice and this permission notice shall be
  included in all copies or substantial portions of the Software.

  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
  OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
  HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
  WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
  OTHER DEALINGS IN THE SOFTWARE.
*)

open XNum
open UTypes
open Logging
open Dim
open Box
  
type page =
  { p_width : num; (* dimensions *) p_height : num;
    p_used : unit PlanePartition.map; (* area covered by boxes *)
    p_boxes : (num * num * box) list
  }

(* list of boxes and their position *)
type area_shape =
  (* an area of the page                          *)
  { as_pos_x : num; (* position of the base line                    *)
    as_pos_y : num; as_width : num; as_height : num;
    (* distance between first and last baseline     *) as_top : num;
    (* maximal amount the area might extend above   *) as_bottom : num
  }

(* the first and below the last baseline        *)
val new_page : num -> num -> page
  
val allocate_rect : page -> num -> num -> num -> num -> page
  
val put_box : page -> num -> num -> box -> page
  
val put_box_on_page : page -> num -> num -> box -> page
  
val find_place_in_area_top :
  page -> area_shape -> dim -> xdim -> dim -> (num * (num * int)) option
  
val find_place_in_area_bottom :
  page -> area_shape -> dim -> xdim -> dim -> (num * (num * int)) option
  
val find_place_in_area_left :
  page -> area_shape -> dim -> (num * (num * int)) option
  
val find_place_in_area_right :
  page -> area_shape -> dim -> (num * (num * int)) option
  
val area_free_vert : page -> area_shape -> (num * num) list
  
val area_free_horiz : page -> area_shape -> (num * num) list
  

